package com.example.process.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.process.ProcessTemplate;
import com.example.process.ProcessType;
import com.example.process.mapper.ProcessTypeMapper;
import com.example.process.service.ProcessTemplateService;
import com.example.process.service.ProcessTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProcessTypeServiceImpl extends ServiceImpl<ProcessTypeMapper, ProcessType> implements ProcessTypeService {

    @Autowired
    private ProcessTemplateService processTemplateService;

    @Override
    public List<ProcessType> findProcessType() {
        //1 查询所有审批分类，返回list集合
        List<ProcessType> processTypes = baseMapper.selectList(null);
        //2遍历返回所有审批分类list集合
        for(ProcessType processType : processTypes){
            //3 得到每个审批分类，根据审批分类id查询对应审批模板
            //审批分类id
            Long typeId = processType.getId();
            //根据审批分类id查询对应审批模板
            List<ProcessTemplate> processTemplateList = processTemplateService.list(Wrappers.<ProcessTemplate>lambdaQuery()
//                    .eq(ProcessTemplate::getId, typeId));
                    .eq(ProcessTemplate::getProcessTypeId, typeId));

            //4 根据审批分类id查询对应审批模板数据（List）封装到每个审批分类对象里面
            processType.setProcessTemplateList(processTemplateList);
        }
        return processTypes;
    }

}
